<?php
/**
 * Created by PhpStorm.
 * User: changshuiwang
 * Date: 2016/7/29
 * Time: 11:37
 */

namespace common\service;
use backend\config\AuthDef;
use yii;

class AuthSrv
{
    public static function assignAuth($type,$id)
    {
        try{
            $auth=Yii::$app->authManager;
            $role=$auth->getRole(AuthDef::$auth_type_arr[$type]);
            $auth->assign($role,$id);
        }catch(Exception $e){
            throw new yii\base\Exception("权限赋予失败");
        }
    }
    public static function getRole($id)
    {
        $auth=Yii::$app->authManager;
        return $auth->getRolesByUser($id);
    }
}